package com.example.starterdef.di.controller;

import com.example.wordfilter.service.DFAWordBean;
import com.example.wordfilter.service.WordBean;

import jakarta.annotation.Resource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Set;

@RestController
@RequestMapping("wordfilter")
public class WordFilterStarterController {
    private static final Logger LOGGER = LoggerFactory.getLogger(WordFilterStarterController.class);
    @Resource
    private WordBean sensitiveWordBean;
    @Resource
    private DFAWordBean dfaSensitiveWordBean;

    //http://localhost:8080/wordfilter/getSensorWord?text=我热烈马比
    @RequestMapping(value = "/getSensorWord",method = {RequestMethod.GET})
    public String getSensorWord(@RequestParam String text) {
        Set<String> set = sensitiveWordBean.getCensorWord(text);
        if(set.isEmpty()){
            LOGGER.info("没有查询到敏感词");
        }else{
            LOGGER.info("已查询到敏感词: {}", set);
        }
        return sensitiveWordBean.getCensorWordText(text);
    }

    //http://localhost:8080/sensorWordDFA/getSensorWord?text=我热烈马比
    @RequestMapping(value = "/sensorWordDFA",method = {RequestMethod.GET})
    public String sensorWordDfa(@RequestParam String text) {
        Set<String> set = dfaSensitiveWordBean.getCensorWord(text);
        if(set.isEmpty()){
            LOGGER.info("没有查询到敏感词");
        }else{
            LOGGER.info("已查询到敏感词: {}", set);
        }
        return dfaSensitiveWordBean.getCensorWordText(text);
    }
}
